package alscript.lua.bridge.util.log;

import com.imy.luasupport.core.LuaCore;
import com.imy.luasupport.util.LLog;

import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.TwoArgFunction;

import alscript.lua.bridge.util.BaseFunLib;
import alscript.lua.bridge.util.LibRegister;

@LibRegister(libName = "log")
public class LogLib extends BaseFunLib {


  public LogLib() {

  }

  @Override
  protected void addFunction(LuaTable lib) {
      lib.set("i",new iFun());
      lib.set("e",new eFun());

  }

  static final class eFun extends TwoArgFunction {

    @Override
    public LuaValue call(LuaValue arg1, LuaValue arg2) {
      String tag = arg1.checkjstring();
      String msg = arg2.checkjstring();
      LLog.e(tag,msg);
      return LuaValue.valueOf(0);
    }
  }
  static final class iFun extends TwoArgFunction {
    @Override
    public LuaValue call(LuaValue arg1, LuaValue arg2) {
      String tag = arg1.checkjstring();
      String msg = arg2.checkjstring();
      LLog.i(tag,msg);
      return LuaValue.valueOf(0);
    }
  }
}
